<?php
class DBMFilterGroupTranslator implements DBMTranslator {
	
	public static function translateToMySQL($translatable, $command = null) {
		// get the filters
		$filters 				= $translatable->getFilters();
		$translatedFilters 	= array();
		
		// translate the filters
		foreach($filters as $filter){
			$translatedFilters[] = $filter->toSQL(DBManager::TYPE_MYSQL, $command);
		}
		
		// implode
		if($translatable->getType() == DBMFilterGroup::AND_GROUP){
			$sql = "( " . implode(" AND ", $translatedFilters) . " )";
		} else {
			$sql = "( " . implode(" OR ", $translatedFilters) . " )";
		}
		
		return $sql;
	}
	public static function translateToPostgreSQL($translatable, $command = null) {
		// get the filters
		$filters 				= $translatable->getFilters();
		$translatedFilters 	= array();
		
		// translate the filters
		foreach($filters as $filter){
			$translatedFilters[] = $filter->toSQL(DBManager::TYPE_POSTGRESQL, $command);
		}
		
		// implode
		if($translatable->getType() == DBMFilterGroup::AND_GROUP){
			$sql = "( " . implode(" AND ", $translatedFilters) . " )";	
		} else {
			$sql = "( " . implode(" OR ", $translatedFilters) . " )";
		}
		
		return $sql;
	}
	public static function translateToSQLServer($translatable, $command = null) {
		// get the filters
		$filters 				= $translatable->getFilters();
		$translatedFilters 	= array();
		
		// translate the filters
		foreach($filters as $filter){
			$translatedFilters[] = $filter->toSQL(DBManager::TYPE_MSSQL, $command);
		}
		
		// implode
		if($translatable->getType() == DBMFilterGroup::AND_GROUP){
			$sql = "( " . implode(" AND ", $translatedFilters) . " )";
		} else {
			$sql = "( " . implode(" OR ", $translatedFilters) . " )";
		}
		
		return $sql;
	}
}

?>
